package com.UnionPayCenter.account.service.impl;

import com.UnionPayCenter.util.IdGen;
import com.UnionPayCenter.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.UnionPayCenter.account.annotation.PayService;
import com.UnionPayCenter.account.entity.ChargeBill;
import com.UnionPayCenter.account.entity.dto.ChargeDTO;
import com.UnionPayCenter.account.entity.dto.PayDTO;
import com.UnionPayCenter.account.enums.ChargeStatusEnum;
import com.UnionPayCenter.account.enums.PayChannelEnum;
import com.UnionPayCenter.account.manager.ChargeBillManager;
import com.UnionPayCenter.account.service.AccountService;
import com.UnionPayCenter.entity.ShopInfoEntity;
import com.UnionPayCenter.entity.dto.ChargeResponse;

/**
 * 会员导入赠送账户余额
 */
@PayService(value = "importService", channel = PayChannelEnum.IMPORT)
public class ImportService implements com.UnionPayCenter.account.service.PayService {

    @Autowired
    private AccountService accountService;

    @Autowired
    private ChargeBillManager chargeBillManager;

    @Override
    public void pay(PayDTO payDTO) {
        // TODO Auto-generated method stub

    }

    @Override
    public ChargeResponse charge(ChargeBill chargeBill, ChargeDTO chargeDTO, ShopInfoEntity shopInfo) {
        //chargeBill.setThirdSn(chargeDTO.getSn());
        chargeBill.setSn(chargeDTO.getSn());
        chargeBill.setState(ChargeStatusEnum.SUCCESS);
        if (StringUtils.isBlank(chargeDTO.getSn())) {
            chargeBill.setSn(IdGen.newStringId());
        }
        //chargeBillManager.saveChargeBill(chargeBill);
        if (chargeDTO.isChargeDirect()) {
            accountService.charge(chargeDTO.getAccountId(), chargeDTO.getAmount(), null);
        }

        return null;
    }

}
